<%--
  Created by IntelliJ IDEA.
  User: Alta Y
  Date: 2019/9/28
  Time: 20:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.min.css" />
    <script src="js/jquery.min.js"></script>
    <link rel="stylesheet" href="css/font.css">
    <link rel="stylesheet" href="css/xadmin.css">

    <script src="lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/xadmin.js"></script>


    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        .page .pagination li{
            margin: 0;
            float: left;
        }
        .page .pagination li span{
            padding: 0;
            border: none;
        }
    </style>
</head>

<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">资讯中心</a>
                <a>
                    <cite>资讯编辑</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body" style="padding-top: 16px;">

                    <form class="layui-form layui-col-space5" id="search" style="float:left;">
                        <div class="layui-input-inline layui-show-xs-block">
                            <input class="layui-input" placeholder="公告id" name="notify_id" ></div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <input class="layui-input" placeholder="标题" name="title" ></div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <select name="state" lay-verify="">
                                <option value="">请选择公告状态</option>
                                <option value="5">待审核</option>
                                <option value="1">草稿</option>
                                <option value="2">已驳回</option>
                                <option value="3">审核通过</option>
                                <option value="4">已发布</option>
                            </select>
                        </div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <button class="layui-btn" lay-filter="search" lay-submit="" style="margin-top: 0px;">
                                <i class="layui-icon">&#xe615;</i>搜索</button>
                        </div>
                    </form>
                    <c:if test="${user.role_type == 3}">
                    <button class="layui-btn layui-btn-danger" onclick="delAll()" style="margin-top: 0;float: right"><i class="layui-icon"></i>批量删除</button>

                        <button class=" layui-btn" onclick="location.href='infoadd'" style="margin-top: 0;float: right;margin-right: 10px;">
                            <i class="layui-icon"></i>添加公告
                        </button>
                    </c:if>
                </div>

                <div class="layui-card-body " style="clear: both">
                    <!-- 公告列表 -->
                    <div class="layui-col-md12">

                        <table class="layui-table layui-form">
                                    <colgroup>
                                        <col >
                                        <col width="150">
                                        <col>
                                        <col width="200">
                                        <col width="200">
                                        <col width="300">
                                    </colgroup>
                                    <thead>
                                    <tr >
                                        <th><input type="checkbox" lay-filter="checkall" name="" lay-skin="primary"></th>
                                        <th>id</th>
                                        <th>标题</th>
                                        <th>创建时间</th>
                                        <th>状态</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <c:forEach items="${pageInfo.list}" var="info">
                                        <tr>
                                            <td>
                                                <c:if test="${info.state != 5}">
                                                <input type="checkbox" name="id" value="${info.notify_id}"   lay-skin="primary"></c:if>
                                            </td>
                                            <td>${info.notify_id}</td>
                                            <td>${info.title}</td>
                                            <td><fmt:formatDate value="${info.create_date}" pattern="yyyy-MM-dd HH:mm:ss"/></td>

                                            <td>
                                                <c:if test="${info.state == 5}">待审核</c:if>
                                                <c:if test="${info.state == 1}">草稿</c:if>
                                                <c:if test="${info.state == 2}">已驳回</c:if>
                                                <c:if test="${info.state == 3}">审核通过</c:if>
                                                <c:if test="${info.state == 4}">已发布</c:if>
                                            </td>
                                            <td class="td-manage">
                                                <c:if test="${info.state==5}">
                                                <a title="查看"  href="/infoview?notify_id=${info.notify_id}&state=0">
                                                    <i class="layui-icon">&#xe67b;</i>查看&thinsp; &thinsp; &thinsp;
                                                </a>
                                                </c:if>
                                                <c:if test="${info.state==1}">
                                                    <a title="查看" href="/infoview?notify_id=${info.notify_id}&state=1">
                                                        <i class="layui-icon">&#xe67b;</i>查看&thinsp; &thinsp; &thinsp;
                                                    </a>
                                                    <!-- 采购人员权限 -->
                                                    <c:if test="${ user.role_type == 3}" >
                                                    <a title="编辑" href="/edit?notify_id=${info.notify_id}">
                                                        <i class="layui-icon">&#xe642;</i>编辑&thinsp; &thinsp; &thinsp;
                                                    </a>
                                                    <a title="删除" onclick="member_del(this,'${info.notify_id}')" href="javascript:;">
                                                        <i class="layui-icon">&#xe640;</i>删除
                                                    </a>
                                                    </c:if>
                                                </c:if>
                                                <c:if test="${info.state==2}">
                                                    <a title="查看"  href="/infoview?notify_id=${info.notify_id}&state=2">
                                                        <i class="layui-icon">&#xe67b;</i>查看&thinsp; &thinsp; &thinsp;
                                                    </a>
                                                    <!-- 采购人员权限 -->
                                                    <c:if test="${ user.role_type == 3}" >
                                                    <a title="编辑"  href="/edit?notify_id=${info.notify_id}">
                                                        <i class="layui-icon">&#xe642;</i>编辑&thinsp; &thinsp; &thinsp;
                                                    </a>
                                                    <a title="删除" onclick="member_del(this,'${info.notify_id}')" href="javascript:;">
                                                        <i class="layui-icon">&#xe640;</i>删除
                                                    </a>
                                                    </c:if>
                                                </c:if>
                                                <c:if test="${info.state==3}">
                                                    <a title="查看"  href="/infoview?notify_id=${info.notify_id}&state=3">
                                                        <i class="layui-icon">&#xe67b;</i>查看&thinsp; &thinsp; &thinsp;
                                                    </a>
                                                    <!-- 采购人员权限 -->
                                                    <c:if test="${ user.role_type == 3}" >
                                                    <a title="发布"  onclick="information_release(this,'${info.notify_id}')" href="javascript:;">
                                                        <i class="layui-icon">&#xe642;</i>发布&thinsp; &thinsp; &thinsp;
                                                    </a>
                                                    <a title="删除" onclick="member_del(this,'${info.notify_id}')" href="javascript:;">
                                                        <i class="layui-icon">&#xe640;</i>删除
                                                    </a>
                                                    </c:if>
                                                </c:if>
                                                <c:if test="${info.state==4}">
                                                    <a title="查看" href="/infoview?notify_id=${info.notify_id}&state=4">
                                                        <i class="layui-icon">&#xe67b;</i>查看&thinsp; &thinsp; &thinsp;
                                                    </a>
                                                    <!-- 采购人员权限 -->
                                                    <c:if test="${ user.role_type == 3}" >
                                                    <a title="删除" onclick="member_del(this,'${info.notify_id}')" href="javascript:;">
                                                        <i class="layui-icon">&#xe640;</i>删除
                                                    </a>
                                                    </c:if>
                                                </c:if>
                                            </td>
                                        </tr>
                                    </c:forEach>
                                    </tbody>
                                </table>
<%--                            </div>--%>

                    </div>
                    <footer class="page">
                        <div class="row">


                            <!--点击分页-->
                            <div class="col-md-12">
                                <nav aria-label="Page navigation">
                                    <ul class="pagination" style="margin-bottom: 0;margin-top: 10px;">

                                        <li><a href="${pageContext.request.contextPath}/infolist?pn=1&notify_id=${keywords[0]}&title=${keywords[1]}&state=${keywords[2]}">首页</a></li>

                                        <!--上一页-->
                                        <li>
                                            <c:if test="${pageInfo.hasPreviousPage}">
                                                <a href="${pageContext.request.contextPath}/infolist?pn=${pageInfo.pageNum-1}&notify_id=${keywords[0]}&title=${keywords[1]}&state=${keywords[2]}" aria-label="Previous">
                                                    <span aria-hidden="true">«</span>
                                                </a>
                                            </c:if>
                                        </li>

                                        <!--循环遍历连续显示的页面，若是当前页就高亮显示，并且没有链接-->
                                        <c:forEach items="${pageInfo.navigatepageNums}" var="page_num">
                                            <c:if test="${page_num == pageInfo.pageNum}">
                                                <li class="active"><a href="#">${page_num}</a></li>
                                            </c:if>
                                            <c:if test="${page_num != pageInfo.pageNum}">
                                                <li><a href="${pageContext.request.contextPath}/infolist?pn=${page_num}&notify_id=${keywords[0]}&title=${keywords[1]}&state=${keywords[2]}">${page_num}</a></li>
                                            </c:if>
                                        </c:forEach>

                                        <!--下一页-->
                                        <li>
                                            <c:if test="${pageInfo.hasNextPage}">
                                                <a href="${pageContext.request.contextPath}/infolist?pn=${pageInfo.pageNum+1}&notify_id=${keywords[0]}&title=${keywords[1]}&state=${keywords[2]}"
                                                   aria-label="Next">
                                                    <span aria-hidden="true">»</span>
                                                </a>
                                            </c:if>
                                        </li>

                                        <li><a href="${pageContext.request.contextPath}/infolist?pn=${pageInfo.pages}&notify_id=${keywords[0]}&title=${keywords[1]}&state=${keywords[2]}">尾页</a></li>
                                    </ul>
                                </nav>
                            </div>
                            <!--文字信息-->
                            <div class="col-md-12">
                                当前第 ${pageInfo.pageNum} 页.总共 ${pageInfo.pages} 页.一共 ${pageInfo.total} 条记录
                            </div>
                        </div>
                    </footer>
                </div>


                <!-- 分页 -->

            </div>
        </div>
    </div>
</div>
</div>

<script>
    layui.use(['form', 'layer', 'jquery'], function(){
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        // 监听checkbox全选
        form.on('checkbox(checkall)', function(data){

            if(data.elem.checked){
                $('tbody input').prop('checked',true);
            }else{
                $('tbody input').prop('checked',false);
            }
            form.render('checkbox');
        });

        form.on('submit(search)',
            function (data) {
                $.ajax({
                    type:"post",
                    url:"/infolist",
                    data:$('#search').serialize(),
                    dataType:"json",
                    success:function (data) {
                        if (data.length > 0){
                            window.location.href="infolist";
                        }else{
                            layer.msg('查无记录', {
                                icon: 1,
                                time: 1000 //1秒关闭（如果不配置，默认是3秒）
                            }, function(){
                                window.location.reload();
                            });
                        }
                    }
                });

            });


    });


    /**批量删除**/
    function delAll (argument) {
        var ids = [];

        // 获取选中的id
        $('tbody input').each(function(index, el) {
            if($(this).prop('checked')){
                ids.push($(this).val())
            }
        });
        if (ids.length == 0){
            layer.msg('至少选中一条记录',{icon:2,time:1000})
            return false;
        }
        layer.confirm('确认要删除吗？',function(index){
            //捉到所有被选中的，发异步进行删除
            $.ajax({
                type:"post",
                url:"/deleteMany",
                data:{"ids":ids.toString()},
                success:function (data) {
                    layer.msg('删除成功', {icon: 1},function(){
                        window.location.reload();
                    });
                }
            });
        });
    }

    /*公告-删除*/
    function member_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            //发异步删除数据
            $.ajax({
                type: "post",
                dataType:"json",
                url: "/deleteInfo",
                data:{"id":id},
                success:function (data) {
                    if(data > 0){
                        layer.msg('删除成功', {
                            icon: 1,
                            time: 1000 //1秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            window.location.reload();
                        });
                    }else{
                        layer.msg('删除失败', {
                            icon: 1,
                            time: 1000 //1秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            window.location.reload();
                        });
                    }
                }
            });
            return false;
        });
    }

    /*公告-发布*/
    function information_release(obj,id){
        layer.confirm('确认要发布吗？',function(index){
            //发异步删除数据

            $.ajax({
                type:"post",
                data:{"id":id},
                url:"/release",
                dataType:"json",
                success:function (data) {
                    if (data > 0){
                        layer.msg('发布成功', {
                            icon: 1,
                            time: 1000 //1秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            window.location.reload();
                        });
                    }

                }
            });
            return false;
        });
    }
</script>
</body>
</html>

